#include "cvector.h"

#include <math.h>

CVector::CVector(float x, float y, float z)
{
    this->m_x = x;
    this->m_y = y;
    this->m_z = z;
}

CVector::CVector(const CVector & V)
{
    this->m_x = V.m_x;
    this->m_y = V.m_y;
    this->m_z = V.m_z;
}

void CVector::operator =(const CVector V)
{
    this->m_x = V.m_x;
    this->m_y = V.m_y;
    this->m_z = V.m_z;
}

CVector CVector::operator +(const CVector V)
{
    return CVector( this->m_x+V.m_x,
                    this->m_y+V.m_y,
                    this->m_z+V.m_z);
}

CVector CVector::operator -(const CVector V)
{
    return CVector( this->m_x-V.m_x,
                    this->m_y-V.m_y,
                    this->m_z-V.m_z);
}

CVector CVector::operator *(const float f)
{
    return CVector (this->m_x*f,
                    this->m_y*f,
                    this->m_z*f);
}

CVector CVector::operator /(const float f)
{
    return CVector (this->m_x/f,
                    this->m_y/f,
                    this->m_z/f);
}

CVector CVector::crossProduct(CVector V)
{
    return CVector(this->m_y*V.m_z - this->m_z*V.m_y,
                   this->m_z*V.m_x - this->m_x*V.m_z,
                   this->m_x*V.m_y - this->m_y*V.m_x);
}

float CVector::dotProduct(const CVector V)
{
    return (this->m_x*V.m_x + this->m_y*V.m_y + this->m_z*V.m_z);
}

float CVector::length()
{
    return sqrt(pow(this->m_x,2)+pow(this->m_y, 2)+pow(this->m_z,2));
}

void CVector::normalize()
{
    (*this) = (*this)/this->length();
}
